using UnityEngine;

public class RailsXConstraint : MonoBehaviour
{
	public Transform Head;

	public ConfigurableJoint Joint;

	public bool FollowPlayer;

	public float Speed;

	private void Update()
	{
		Vector3 localPosition = base.transform.localPosition;
		if (FollowPlayer)
		{
			float x = Head.localPosition.x;
			localPosition.x = Mathf.Lerp(localPosition.x, x, Time.deltaTime * Speed);
			float num = 0f - Joint.linearLimit.limit + Joint.connectedAnchor.x + Joint.connectedBody.transform.localPosition.x;
			if (localPosition.x < num)
			{
				localPosition.x = num;
			}
		}
		if (base.transform.localPosition.x > 0f)
		{
			localPosition.x = 0f;
		}
		base.transform.localPosition = localPosition;
	}
}
